package com.zjbd.douyangcommonquartz.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class QuartzConfig {

    //调度中心部署根地址
    @Value("${douyang.quartz.admin-addresses}")
    private String adminAddresses;
    //执行器AppName
    @Value("${spring.app-name}")
    private String appname;
    //执行器注册的Token
    private String accessToken = "default_token";
    //日志存储路径
    @Value("${douyang.quartz.log-path}")
    private String logPath;
    //日志保存天数
    private int logRetentionDays = 7;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        log.info(">>>>>>>>>>> xxl-job config init.");

        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appname);
        xxlJobSpringExecutor.setIp("");
        xxlJobSpringExecutor.setPort(-1);
        xxlJobSpringExecutor.setAccessToken(accessToken);
        xxlJobSpringExecutor.setLogPath(logPath);
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
        return xxlJobSpringExecutor;
    }

}
